''' 核心思想：对于保存下来的每一个过程，求他的任务相关信息 （2021.4.18 王耀）'''

import os
import model.net as nn
import tool as tl
import numpy as np
import math


def get_params(path):
    loss_path = path + 'loss/'
    distance_path = path + 'result/'
    loss_dirs = os.listdir(loss_path)
    losslist = []
    for loss_dir in loss_dirs:
        loss_array = tl.read_csv(loss_path + loss_dir)
        losslist.append((float(loss_array[0]) - float(loss_array[-1])))

    distance_dirs = os.listdir(distance_path)
    distancelist = []
    for distance_dir in distance_dirs:
        distancelist.append(tl.to_float(tl.read_csv(distance_path + distance_dir))[0][0])

    return np.array(losslist).mean(), np.array(distancelist).mean()


def log_r(KD, standard):
    standard_loss, standard_dis = get_params(standard)
    kd_loss, kd_dis = get_params(KD)
    infor_eff = (kd_loss * standard_dis) / (standard_loss * kd_dis)
    return infor_eff



def input(input_path):
    class_names = os.listdir(input_path)
    KDclass_names = []
    for name in class_names:
        # if not name == 'baseline cnn dropout':
            print('computing the information effectiveness between [{}] and [baseline cnn]'.format(name))
            print(log_r(input_path + name + '/', input_path + 'baseline 2layer cnn/'))

input('weights_params/IE demo val loss 160 epoch_random/')